function plotPC_fig3(N,K,PI,lengthOfPI,EbN0dBrange,designSNRdB,verbose_output_flag) %designSNRdB is optional

global PCparams;

if nargin==4 %if last 2 args are not supplied
    EbN0dBrange = 0:1:2; %default SNR range to quickly see the o/p
    designSNRdB = 0; 
    verbose_output_flag=0;
elseif nargin==5
    designSNRdB=0;
    verbose_output_flag=0;
elseif nargin==6
    verbose_output_flag=0;
elseif (nargin>7 || nargin<4)
    fprintf('\n   Usage: plotPC(N,K,EbN0dBrange,designSNRdB,verbose_output_flag)\n');
    fprintf('\n       N  -  Blocklength');
    fprintf('\n       K  -  Message length (Rate = K/N)');
    fprintf('\n       EbN0dBrange -  the range of Eb/N0 values in dB');
    fprintf('\n                           to Monte-Carlo simulate)');
    fprintf('\n       designSNRdB (optional) - the SNR at which the polar code should be constructed');
    fprintf('\n                                 (Here, SNR=Ec/N0 - by definition for a PCC, defaults to "0dB")');
    fprintf('\n       verbose_output_flag - whether to print detailed status of the simulation periodically\n\n');
    return;
end

PCparams1 = PCparams; %store the current

%initPC(N,K,1,2, designSNRdB,1); %silent, no output

EbN0dB = EbN0dBrange;

MCsize = 5; %Montecarlo size

global BER;


BER = zeros(lengthOfPI*2+1,length(EbN0dB));


if(~verbose_output_flag)
    fprintf('Completed SNR points (out of %d): ',length(EbN0dB));
end

for i=1:lengthOfPI*2+1
    if(i==1) 
        initPC(N,K,1,2, designSNRdB,0,1); %SCD+SCC
    elseif(i <= 6)
        initPC(N,K,1,2, designSNRdB,0,1,PI(i-1,:));%PSCD+SCC
    else
        initPC(N,K,1,2, designSNRdB,1,1,PI(i-6,:)); %PSCD+PSCC
    end

    for j=1:length(EbN0dB)
    tt=tic();
        N0 = PCparams.N0;
        Ec = (K/N)*N0*10^(EbN0dB(j)/10);

        PCparams.Ec = Ec; %normalized Ec %necessary for pencode(), pdecode()

        for l=1:MCsize
            tic
            u=randi(2,K,1)-1; %Bernoulli(0.5)
            x=pencode(u);
            txvec = (2*x-1)*sqrt(Ec);
            y = txvec + sqrt(N0/2)*randn(N,1);
            
            uhat = pdecode(y);
            
            nfails = sum(uhat ~= u);
            
            BER(i,j) = BER(i,j) + nfails;
            
            if(verbose_output_flag)
            if mod(l,200)==0
            fprintf('Eb/N0 = %.1f dB and iteration-%d: %.2f sec : %d BEs %c',EbN0dB(j),l,toc,BER(i,j),char(10)); %DEBUG NOTE
            end
            end

            if l>=1000  %frame errors, sufficient to stop
                break;
            end
        end
        
        BER(i,j) = BER(i,j)/(K*l);
    if(verbose_output_flag)
        toc(tt);
    else
        fprintf('\n %.2f dB (time taken:%.2f sec)',EbN0dB(j),toc(tt));
    end
    end
end
x = EbN0dBrange;
semilogy(x,BER(1,:),'k-','linewidth',2,'Markersize',15);
hold on;
semilogy(x,BER(2,:),'r+-',x,BER(3,:),'r*-',x,BER(4,:),'rs-',x,BER(5,:),'ro-',x,BER(6,:),'rd-');
grid on;

semilogy(x,BER(7,:),'m+-',x,BER(8,:),'m*-',x,BER(9,:),'ms-',x,BER(10,:),'mo-',x,BER(11,:),'md-')
axis([0,2.8,0.0001,1]);
xlabel('Eb/N0 in dB');
ylabel('Bit Error Rate');
legend('SCD',...
    '-PSCD with SCC[0 1 2 3 4 5 6 7 8 9]',...
    '-PSCD with SCC[5 1 8 7 4 3 2 6 9 0]',...
    '-PSCD with SCC[0 8 6 2 4 3 5 7 9 1]',...
    '-PSCD with SCC[3 9 2 4 5 0 1 8 6 7]',...
    '-PSCD with SCC[4 6 2 7 5 3 8 1 9 0]',...
    '-PSCD with PSCC[0 1 2 3 4 5 6 7 8 9]',...
    '-PSCD with PSCC[5 1 8 7 4 3 2 6 9 0]',...
    '-PSCD with PSCC[0 8 6 2 4 3 5 7 9 1]',...
    '-PSCD with PSCC[3 9 2 4 5 0 1 8 6 7]',...
    '-PSCD with PSCC[4 6 2 7 5 3 8 1 9 0]','fontsize',5);
hold off;
PCparams=PCparams1; %restore the original
end